package com.wang.rabbitmqstudy.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import java.io.IOException;

/**
 * 测优先级队列的时候，先把消费者关掉。边加边消费的话看不出来，因为消费速度太快了
 * 还有一个是要注意数据设置的priority不要超过队列的x-max-priority。
 */
@Component
public class PriorityQueueHandler {
    @RabbitListener(queues = {"argumentsPriorityQueue"})
    @RabbitHandler
    public void execute(Channel channel, Message message) throws InterruptedException, IOException {
        System.out.println((new String(message.getBody()) + message.getMessageProperties().getPriority()));
        // 手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
